package cn.dubito.sshl.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


import com.opensymphony.xwork2.ActionSupport;

import cn.dubito.sshl.common.PageModel;
import cn.dubito.sshl.domain.Notice;
import cn.dubito.sshl.service.NoticeService;

/**
 * NoticeAction
 */
public class NoticeAction extends ActionSupport {
	
	private static final long serialVersionUID = 444562046424811426L;
	/** 公告集合 */
	private List<Notice> notices;
	/** 分页实体 */
	private PageModel pageModel = new PageModel();
	private Notice notice;
	private String keyword;
	
	@Autowired  // byType
	@Qualifier("noticeService") // byName
	private NoticeService noticeService;
	
	/** 分页查询公告 */
	public String selectNotice(){
		notices = noticeService.getNoticeByPage(pageModel);
		return SUCCESS;
	}
	/** 添加公告 */
	public String addNotice(){
		noticeService.saveNotice(notice);
		return SUCCESS;
	}
	
	/** 跳转到修改公告的页面 */
	public String showUpdateNotice(){
		notice = noticeService.getNotice(notice.getId());
		return SUCCESS;
	}
	/** 修改公告 */
	public String updateNotice(){
		noticeService.updateNotice(notice);
		return SUCCESS;
	}
	/** 删除公告 */
	public String deleteNotice(){
		noticeService.deleteNotice(notice.getId());
		return SUCCESS;
	}
	
	/** 全文检索方法 */
	public String search(){
		pageModel.setPageSize(7);
		notices = noticeService.search(keyword, pageModel);
		return SUCCESS;
	}
	
	
	/** setter and getter方法 */
	public PageModel getPageModel() {
		return pageModel;
	}
	public void setPageModel(PageModel pageModel) {
		this.pageModel = pageModel;
	}
	public List<Notice> getNotices() {
		return notices;
	}
	public Notice getNotice() {
		return notice;
	}
	public void setNotice(Notice notice) {
		this.notice = notice;
	}
	public String getKeyword() {
		return keyword;
	}
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	
	
	
}
